package com.itheima.d7_IO.BufferedWriter;

import java.io.*;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;

public class Test2 {
    public static void main(String[] args) {
         List<String> list = new ArrayList<>();
        try (
                Reader fileReader = new FileReader("E:\\FileResource\\Test.txt");
                BufferedReader bufferedReader = new BufferedReader(fileReader);
                FileWriter fileWriter = new FileWriter("E:\\FileResource\\2.txt");
                BufferedWriter bufferedWriter = new BufferedWriter(fileWriter);
        ) {
             String s;
             while((s = bufferedReader.readLine()) != null) {
                 list.add(s);
            }
            System.out.println(list);
             //如果前面的序号是中文 一
            // 那么List<String> list2= new ArrayList<>();
            // Collections.addAll(list2,"一","二")
            // 这样每个对应的中文的索引  list2.indexOf(”一“) 就能得到大小了
             list.sort(new Comparator<String>() {
                 @Override
                 public int compare(String o1, String o2) {
                     int index1 =o1.indexOf(".");
                     int index2 =o2.indexOf(".");
                     String s1 = o1.substring(0, index1);
                     int i1 = Integer.parseInt(s1);
                     String s2 = o2.substring(0, index2);
                     int i2 = Integer.parseInt(s2);
                     return i1 - i2 ;
                 }
             });
            for (String s1 : list) {
                bufferedWriter.write(s1);
                bufferedWriter.newLine();
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
